home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / c / cd.c < prev    next >
C/C++ Source or Header  |  1996-09-13  |  2KB  |  121 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: cd.c,v 1.4 1996/09/13 17:52:09 digulla Exp $
  4.     $Log: cd.c,v $
  5.     Revision 1.4  1996/09/13 17:52:09  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.3  1996/08/13 15:34:04  digulla
  9.     #include <exec/execbase.h> was missing
  10.  
  11.     Revision 1.2  1996/08/01 17:40:43  digulla
  12.     Added standard header for all files
  13.  
  14.     Desc:
  15.     Lang:
  16. */
  17. #include <exec/execbase.h>
  18. #include <exec/memory.h>
  19. #include <clib/exec_protos.h>
  20. #include <dos/dos.h>
  21. #include <clib/dos_protos.h>
  22. #include <utility/tagitem.h>
  23.  
  24. CALLENTRY /* Before the first symbol */
  25.  
  26. struct ExecBase *SysBase;
  27. struct DosLibrary *DOSBase;
  28.  
  29. static LONG tinymain(void);
  30.  
  31. LONG entry(struct ExecBase *sysbase)
  32. {
  33.     LONG error=RETURN_FAIL;
  34.     SysBase=sysbase;
  35.     DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",39);
  36.     if(DOSBase!=NULL)
  37.     {
  38.     error=tinymain();
  39.     CloseLibrary((struct Library *)DOSBase);
  40.     }
  41.     return error;
  42. }
  43.  
  44. static LONG tinymain(void)
  45. {
  46.     STRPTR args[1]={ 0 };
  47.     struct RDArgs *rda;
  48.     BPTR dir;
  49.     STRPTR buf;
  50.     ULONG i;
  51.     struct FileInfoBlock *fib;
  52.     LONG error=0;
  53.  
  54.     rda=ReadArgs("DIR",(IPTR *)args,NULL);
  55.     if(rda!=NULL)
  56.     {
  57.     if(args[0])
  58.     {
  59.         dir=Lock(args[0],ACCESS_READ);
  60.         if(dir)
  61.         {
  62.         fib=AllocDosObject(DOS_FIB,NULL);
  63.         if(fib!=NULL)
  64.         {
  65.             if(Examine(dir,fib))
  66.             {
  67.             if(fib->fib_DirEntryType>0)
  68.                 dir=CurrentDir(dir);
  69.             else
  70.             {
  71.                 SetIoErr(ERROR_DIR_NOT_FOUND);
  72.                 error=RETURN_ERROR;
  73.             }
  74.             }else
  75.             error=RETURN_ERROR;
  76.             FreeDosObject(DOS_FIB,fib);
  77.         }else
  78.         {
  79.             SetIoErr(ERROR_NO_FREE_STORE);
  80.             error=RETURN_ERROR;
  81.         }
  82.         UnLock(dir);
  83.         }else
  84.         error=RETURN_ERROR;
  85.     }else
  86.     {
  87.         dir=CurrentDir(0);
  88.         for(i=256;;i+=256)
  89.         {
  90.         buf=AllocVec(i,MEMF_ANY);
  91.         if(buf==NULL)
  92.         {
  93.             SetIoErr(ERROR_NO_FREE_STORE);
  94.             error=RETURN_ERROR;
  95.             break;
  96.         }
  97.         if(NameFromLock(dir,buf,i))
  98.         {
  99.             if(FPuts(Output(),buf)<0||
  100.                FPuts(Output(),"\n")<0)
  101.             error=RETURN_ERROR;
  102.             FreeVec(buf);
  103.             break;
  104.         }
  105.         FreeVec(buf);
  106.         if(IoErr()!=ERROR_LINE_TOO_LONG)
  107.         {
  108.             error=RETURN_ERROR;
  109.             break;
  110.         }
  111.         }
  112.         CurrentDir(dir);
  113.     }
  114.     FreeArgs(rda);
  115.     }else
  116.     error=RETURN_FAIL;
  117.     if(error)
  118.     PrintFault(IoErr(),"CD");
  119.     return error;
  120. }
  121.